package com.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.dao.mybatis.mapper.UserMapper;
import com.entity.Pagination;
import com.entity.User;

@Repository
public class UserDaoImp implements UserDao {
	@Resource
	private UserMapper mapper;

	@Override
	public List<User> getAllUsers(Pagination pagination,User User) {
		Map<String, Object>map = new HashMap<String, Object>();
		if(pagination!=null){
			map.put("page", pagination.getCurrentPage());
			map.put("startRow", pagination.getStartRow());
			map.put("pageSize", pagination.getEveryPage());
			
		}
		if(User!=null){
			map.put("userName", User.getUserName());	
			map.put("roleId", User.getRoleId());
		}
		return mapper.getAllUsers(map);
	}

	@Override
	public Integer insertUser(User User) {
		return mapper.insert(User);
	}

	@Override
	public Integer deleteUser(User User) {
		if(User==null){return -1;}
		return mapper.deleteByPrimaryKey(User.getId());
	}

	@Override
	public Integer updateUser(User User) {
		return mapper.updateByPrimaryKey(User);
	}

	@Override
	public int countAll(User User) {
		return mapper.countAll(User);
	}

	@Override
	public User findById(Integer id) {
		return mapper.findById(id);
	}

	@Override
	public User findUser(User user) {
		return mapper.findUser(user);
	}
}
